import React from 'react';
import { Container, Box, Typography } from '@mui/material';
import { PostProvider } from '../features/community/contexts/PostContext';
import { PostList } from '../features/community/components/PostList';
import { useAuth } from '../features/auth/AuthContext';

// 用户帖子页面组件
const UserPostsPageContent: React.FC = () => {
  const { user } = useAuth();
  
  if (!user) {
    return (
      <Container maxWidth="lg">
        <Box sx={{ py: 4, textAlign: 'center' }}>
          <Typography variant="h5" color="error">
            请先登录后查看您的帖子
          </Typography>
        </Box>
      </Container>
    );
  }

  return (
    <Container maxWidth="lg">
      <Box sx={{ py: 4 }}>
        <Typography variant="h4" sx={{ mb: 4, fontWeight: 'bold', textAlign: 'center' }}>
          我的帖子
        </Typography>
        <PostList userId={Number(user.id)} />
      </Box>
    </Container>
  );
};

// 导出包装了 PostProvider 的主组件
export const UserPostsPage: React.FC = () => {
  return (
    <PostProvider>
      <UserPostsPageContent />
    </PostProvider>
  );
};